﻿XIncludeFile "Function.pb"
XIncludeFile "LenDate.pb"
;==============================函数类型===============================

;==================================常数==================================
Enumeration
 #Style=1
 #Visible=2
 #Enabled=4
EndEnumeration

;==============================窗口结构==============================
Structure DateFtv
  Day.l
  X.l
  Y.l
  Width.l
  Height.l
  DayText.text
  LYear.l
  LMonth.l
  LDay.l
  IsLeap.B
  LDayText.text
  sFtv.s  ;阳历节日
  lFtv.s  ;阴历节日
  wFtv.s  ;星期节日
  tFtv.s  ;24个节气
  eFtv.s  ;黑色星期天
  aFtv.s  ;获得星座
  
  Image.l
  ToDayImage.l
  OnImage.l  
  BackImage.l
EndStructure

Structure GdipDate Extends PWnd
  Style.B
  MouseStrar.l
  Year.l
  Month.l
  Day.l
  
  DayWidth.l
  DayHeight.l
  DayTop.l
  DText.Text
  LDText.Text
  DateArray.DateFtv[42]
  Ftv.B      ;节日显视方式
  sColor.l   ;阳历节日的颜色
  lColor.l   ;阴历节日的颜色
  wColor.l   ;星期节日的颜色
  tColor.l   ;24个节气的颜色
  SundayColor.l
  SaturdayColor.l
  
  IsBack.b
  BackYearText.text

  IsWeek.b
  WeekText.text

  IsTitle.b
  sTitle.text
  lTitle.text
  wTitle.text
  TeitleX.l
  TeitleY.l
  TeitleWidth.l
  TeitleHeight.l
  
  ToDayImage.l  ;今天的图片
  OnImage.l  
  MoveColor.l 
  WeekImage.l
  TitleImage.l
  
  TitleBack.l
EndStructure


;================================函数===========================================

Procedure SetStartDate(*Date.GdipDate)
 Height = *Date\ DayTop
 
 If *Date\IsTitle
   Height + *Date\sTitle\Height
 EndIf
 
 If *Date\IsWeek
   Height + *Date\WeekText\Height
 EndIf
 
 For I=0 To 36 Step 7
  *Ftv.DateFtv=*Date\DateArray[I]
  *Ftv\X=0 * *Date\DayWidth
  *Ftv\Y=Height
  *Ftv\Width = *Date\DayWidth
  *Ftv\Height = *Date\DayHeight
  CopyMemory(*Date\DText,*Ftv\DayText,SizeOf(Text))
  *Ftv\DayText\TextColor=*Date\SundayColor
  *Ftv\DayText\X=*Ftv\X+*Date\DText\X
  *Ftv\DayText\Y=*Ftv\Y+*Date\DText\Y
  CopyMemory(*Date\LDText,*Ftv\LDayText,SizeOf(Text))
  *Ftv\LDayText\X=*Ftv\X+*Date\LDText\X
  *Ftv\LDayText\Y=*Ftv\Y+*Date\LDText\Y

  *Ftv.DateFtv=*Date\DateArray[I+1]
  *Ftv\X=1 * *Date\DayWidth
  *Ftv\Y=Height
  *Ftv\Width = *Date\DayWidth
  *Ftv\Height = *Date\DayHeight
  CopyMemory(*Date\DText,*Ftv\DayText,SizeOf(Text))
  *Ftv\DayText\X=*Ftv\X+*Date\DText\X
  *Ftv\DayText\Y=*Ftv\Y+*Date\DText\Y
  CopyMemory(*Date\LDText,*Ftv\LDayText,SizeOf(Text))
  *Ftv\LDayText\X=*Ftv\X+*Date\LDText\X
  *Ftv\LDayText\Y=*Ftv\Y+*Date\LDText\Y
  
  
  *Ftv.DateFtv=*Date\DateArray[I+2]
  *Ftv\X=2 * *Date\DayWidth
  *Ftv\Y=Height
  *Ftv\Width = *Date\DayWidth
  *Ftv\Height = *Date\DayHeight
  CopyMemory(*Date\DText,*Ftv\DayText,SizeOf(Text))
  *Ftv\DayText\X=*Ftv\X+*Date\DText\X
  *Ftv\DayText\Y=*Ftv\Y+*Date\DText\Y
  CopyMemory(*Date\LDText,*Ftv\LDayText,SizeOf(Text))
  *Ftv\LDayText\X=*Ftv\X+*Date\LDText\X
  *Ftv\LDayText\Y=*Ftv\Y+*Date\LDText\Y
  
  *Ftv.DateFtv=*Date\DateArray[I+3]
  *Ftv\X=3 * *Date\DayWidth
  *Ftv\Y=Height
  *Ftv\Width = *Date\DayWidth
  *Ftv\Height = *Date\DayHeight
  CopyMemory(*Date\DText,*Ftv\DayText,SizeOf(Text))
  *Ftv\DayText\X=*Ftv\X+*Date\DText\X
  *Ftv\DayText\Y=*Ftv\Y+*Date\DText\Y
  CopyMemory(*Date\LDText,*Ftv\LDayText,SizeOf(Text))
  *Ftv\LDayText\X=*Ftv\X+*Date\LDText\X
  *Ftv\LDayText\Y=*Ftv\Y+*Date\LDText\Y
  
  *Ftv.DateFtv=*Date\DateArray[I+4]
  *Ftv\X=4 * *Date\DayWidth
  *Ftv\Y=Height
  *Ftv\Width = *Date\DayWidth
  *Ftv\Height = *Date\DayHeight
  CopyMemory(*Date\DText,*Ftv\DayText,SizeOf(Text))
  *Ftv\DayText\X=*Ftv\X+*Date\DText\X
  *Ftv\DayText\Y=*Ftv\Y+*Date\DText\Y
  CopyMemory(*Date\LDText,*Ftv\LDayText,SizeOf(Text))
  *Ftv\LDayText\X=*Ftv\X+*Date\LDText\X
  *Ftv\LDayText\Y=*Ftv\Y+*Date\LDText\Y
  
  *Ftv.DateFtv=*Date\DateArray[I+5]
  *Ftv\X=5 * *Date\DayWidth
  *Ftv\Y=Height
  *Ftv\Width = *Date\DayWidth
  *Ftv\Height = *Date\DayHeight
  CopyMemory(*Date\DText,*Ftv\DayText,SizeOf(Text))
  *Ftv\DayText\X=*Ftv\X+*Date\DText\X
  *Ftv\DayText\Y=*Ftv\Y+*Date\DText\Y
  CopyMemory(*Date\LDText,*Ftv\LDayText,SizeOf(Text))
  *Ftv\LDayText\X=*Ftv\X+*Date\LDText\X
  *Ftv\LDayText\Y=*Ftv\Y+*Date\LDText\Y
  
  *Ftv.DateFtv=*Date\DateArray[I+6]
  *Ftv\X=6 * *Date\DayWidth
  *Ftv\Y=Height
  *Ftv\Width = *Date\DayWidth
  *Ftv\Height = *Date\DayHeight
  CopyMemory(*Date\DText,*Ftv\DayText,SizeOf(Text))
  *Ftv\DayText\TextColor=*Date\SaturdayColor
  *Ftv\DayText\X=*Ftv\X+*Date\DText\X
  *Ftv\DayText\Y=*Ftv\Y+*Date\DText\Y
  CopyMemory(*Date\LDText,*Ftv\LDayText,SizeOf(Text))
  *Ftv\LDayText\X=*Ftv\X+*Date\LDText\X
  *Ftv\LDayText\Y=*Ftv\Y+*Date\LDText\Y
  Height + *Date\DayHeight
 Next   
EndProcedure

Procedure SetArrayDate(*Date.GdipDate)
   Day=SolarDays(*Date\Year,*Date\Month)
   Week=Weekday(*Date\Year,*Date\Month,1)
   SWeek=YearGetAllDay(*Date\Year,*Date\Month,D)
   *Ftv.DateFtv=*Date\DateArray[Week + Day(Date()) -1]
   If *Date\Year=Year(Date()) And *Date\Month=Month(Date())
     *Ftv\ToDayImage = *Date\ToDayImage
   EndIf 
   *Ftv\OnImage = *Date\OnImage
   *Date\OnGadget=*Ftv
   For D = 1 To Day 
     *Ftv.DateFtv=*Date\DateArray[Week]
     *Ftv\Day=D
     *Ftv\DayText\Text=Str(D)
     LDate.d=GetLunarNewYear(*Date\Year,*Date\Month,D)
     *Ftv\LYear=PeekC(@LDate)
     *Ftv\LMonth=PeekC(@LDate+2)
     *Ftv\LDay=PeekC(@LDate+4)
     *Ftv\IsLeap=PeekC(@LDate+6)
     
     *Ftv\sFtv=GetsFtv(*Date\Month,D)
     *Ftv\lFtv=GetlFtv(*Ftv\LMonth,*Ftv\LDay)
     *Ftv\wFtv=GetwFtv(*Date\Year,*Date\Month,D)
     *Ftv\tFtv=GetSolarTerm(*Date\Year,*Date\Month,D)
     If SWeek =GetEaster(*Date\Year)
       *Ftv\eFtv="黑色星期天"
     EndIf 
     *Ftv\aFtv=GetAstrology(*Date\Month,D)
     
     If *Ftv\LDay=1
       *Ftv\LDayText\Text=GetChineseMonth(*Ftv\LMonth)
       If *Ftv\IsLeap
         *Ftv\LDayText\Text="闰"+*Ftv\LDayText\Text
         If LGetDay(*Ftv\LYear) =30
           *Ftv\LDayText\Text + "大"
         Else
           *Ftv\LDayText\Text + "小"
         EndIf
       Else
         If lGetMonthDays(*Ftv\LYear,*Ftv\LMonth) = 30
           *Ftv\LDayText\Text + "大"
         Else
           *Ftv\LDayText\Text + "小"
         EndIf
       EndIf 
       *Ftv\LDayText\FontStyle=1
     Else
       *Ftv\LDayText\Text=GetChineseDay(*Ftv\LDay)
     EndIf 
     
     If *Ftv\sFtv
       *Ftv\LDayText\Text=*Ftv\sFtv
       *Ftv\LDayText\TextColor=*Date\sColor
       *Ftv\LDayText\FontStyle=0
     EndIf 
     
     If *Ftv\lFtv
       *Ftv\LDayText\Text=*Ftv\lFtv
       *Ftv\LDayText\TextColor=*Date\lColor
       *Ftv\LDayText\FontStyle=0
     EndIf 
     
     If *Ftv\wFtv
       *Ftv\LDayText\Text=*Ftv\wFtv
       *Ftv\LDayText\TextColor=*Date\wColor
       *Ftv\LDayText\FontStyle=0
     EndIf 
     
     If *Ftv\tFtv
       *Ftv\LDayText\Text=*Ftv\tFtv
       *Ftv\LDayText\TextColor=*Date\tColor
       *Ftv\LDayText\FontStyle=0
     EndIf 
     
     If *Ftv\eFtv
       *Ftv\LDayText\Text=*Ftv\eFtv
       *Ftv\LDayText\TextColor=*Date\wColor
       *Ftv\LDayText\FontStyle=0
     EndIf 

     Week + 1
   Next 
EndProcedure

Procedure DrawTitle(*Date.GdipDate,Day) ;绘制日历标题
  Week=Weekday(*Date\Year,*Date\Month,1)
  *Ftv.DateFtv=*Date\DateArray[Week+Day - 1]
  Temps.s = "公历" + Str(*Date\Year)+"年" +Str(*Date\Month)+ "月"
  ISB = 0
  If Temps <> *Date\sTitle\Text
    *Date\sTitle\Text = Temps 
    ISB  = 1
  EndIf  
  
  Temps = "农历" + Str(*Ftv\LYear)+"年"
  If *Ftv\IsLeap
    Temps + "闰"
    ISB  = 1
  EndIf 
  Temps + Str(*Ftv\LMonth)+"月【" + GetChineseEra(*Ftv\LYear) + GetAnimal(*Ftv\LYear) +"】"
  
  If *Date\lTitle\Text <> Temps
    *Date\lTitle\Text = Temps
  EndIf 
  If  *Date\wTitle\Text <> *Ftv\aFtv
    *Date\wTitle\Text = *Ftv\aFtv
    ISB  = 1
  EndIf 
  Debug Temps
  If ISB
  GdipGetImageGraphicsContext(*Date\Creat\ImageBack,@Graphics)
    If *Date\TitleBack
      GdipSetCompositingMode(Graphics,#CompositingModeSourceCopy)
      GdipDrawImageRect(Graphics,*Date\TitleBack,*Date\TeitleX,*Date\TeitleY,*Date\TeitleWidth,*Date\TeitleHeight)
    Else 
       GdipCreateBitmapFromScan0(*Date\TeitleWidth,*Date\TeitleHeight,0,#GDIPLUS_PIXELFORMAT_32bppARGB, 0,@*Date\TitleBack)
       GdipGetImageGraphicsContext(*Date\TitleBack,@dGraphics)
         GdipSetCompositingMode(dGraphics,#CompositingModeSourceCopy)
         GdipDrawImageRectRectI(dGraphics,*Date\Creat\ImageBack,0,0,*Date\TeitleWidth,*Date\TeitleHeight,*Date\TeitleX,*Date\TeitleY,*Date\TeitleWidth,*Date\TeitleHeight, #UnitPixel,#Null, #Null, #Null)
       GdipDeleteGraphics(dGraphics)
    EndIf 
    
    GdipSetCompositingMode(Graphics,#CompositingModeSourceOver)
    
    If *Date\TitleImage
      GdipDrawImageRect(Graphics,*Date\TitleImage,*Date\TeitleX,*Date\TeitleY,*Date\TeitleWidth,*Date\TeitleHeight)
    EndIf
    
    GdipImageText(Graphics,*Date\sTitle\Text,*Date\sTitle\X ,*Date\sTitle\Y,*Date\sTitle\Width,*Date\sTitle\Height,*Date\sTitle\FontName,*Date\sTitle\FontSize,*Date\sTitle\FontStyle,*Date\sTitle\TextColor,*Date\sTitle\PenColor,*Date\sTitle\PenWidth,*Date\sTitle\Align,*Date\sTitle\Style)
    GdipImageText(Graphics,*Date\lTitle\Text,*Date\lTitle\X ,*Date\lTitle\Y,*Date\lTitle\Width,*Date\lTitle\Height,*Date\lTitle\FontName,*Date\lTitle\FontSize,*Date\lTitle\FontStyle,*Date\lTitle\TextColor,*Date\lTitle\PenColor,*Date\lTitle\PenWidth,*Date\lTitle\Align,*Date\lTitle\Style)
    GdipImageText(Graphics,*Date\wTitle\Text,*Date\wTitle\X ,*Date\wTitle\Y,*Date\wTitle\Width,*Date\wTitle\Height,*Date\wTitle\FontName,*Date\wTitle\FontSize,*Date\wTitle\FontStyle,*Date\wTitle\TextColor,*Date\wTitle\PenColor,*Date\wTitle\PenWidth,*Date\wTitle\Align,*Date\wTitle\Style)
  GdipDeleteGraphics(Graphics)
  EndIf 
EndProcedure

Procedure DrawWeekT(*Date.GdipDate,Y) ;绘制星期标题
  GdipGetImageGraphicsContext(*Date\Creat\ImageBack,@Graphics)
     If *Date\WeekImage
       For I=0 To 6
         GdipDrawImageRect(Graphics,*Date\WeekImage,I * *Date\WeekText\Width,Y,*Date\WeekText\Width,*Date\WeekText\Height)
       Next 
     EndIf 
     GdipImageText(Graphics,"日",0 * *Date\WeekText\Width ,Y,*Date\WeekText\Width,*Date\WeekText\Height,*Date\WeekText\FontName,*Date\WeekText\FontSize,*Date\WeekText\FontStyle,*Date\DateArray[0]\DayText\TextColor,*Date\DateArray[0]\DayText\TextColor,*Date\WeekText\PenWidth,*Date\WeekText\Align,*Date\WeekText\Style)
     GdipImageText(Graphics,"一",1 * *Date\WeekText\Width ,Y,*Date\WeekText\Width,*Date\WeekText\Height,*Date\WeekText\FontName,*Date\WeekText\FontSize,*Date\WeekText\FontStyle,*Date\WeekText\TextColor,*Date\WeekText\PenColor,*Date\WeekText\PenWidth,*Date\WeekText\Align,*Date\WeekText\Style)
     GdipImageText(Graphics,"二",2 * *Date\WeekText\Width ,Y,*Date\WeekText\Width,*Date\WeekText\Height,*Date\WeekText\FontName,*Date\WeekText\FontSize,*Date\WeekText\FontStyle,*Date\WeekText\TextColor,*Date\WeekText\PenColor,*Date\WeekText\PenWidth,*Date\WeekText\Align,*Date\WeekText\Style)
     GdipImageText(Graphics,"三",3 * *Date\WeekText\Width ,Y,*Date\WeekText\Width,*Date\WeekText\Height,*Date\WeekText\FontName,*Date\WeekText\FontSize,*Date\WeekText\FontStyle,*Date\WeekText\TextColor,*Date\WeekText\PenColor,*Date\WeekText\PenWidth,*Date\WeekText\Align,*Date\WeekText\Style)
     GdipImageText(Graphics,"四",4 * *Date\WeekText\Width ,Y,*Date\WeekText\Width,*Date\WeekText\Height,*Date\WeekText\FontName,*Date\WeekText\FontSize,*Date\WeekText\FontStyle,*Date\WeekText\TextColor,*Date\WeekText\PenColor,*Date\WeekText\PenWidth,*Date\WeekText\Align,*Date\WeekText\Style)
     GdipImageText(Graphics,"五",5 * *Date\WeekText\Width ,Y,*Date\WeekText\Width,*Date\WeekText\Height,*Date\WeekText\FontName,*Date\WeekText\FontSize,*Date\WeekText\FontStyle,*Date\WeekText\TextColor,*Date\WeekText\PenColor,*Date\WeekText\PenWidth,*Date\WeekText\Align,*Date\WeekText\Style)
     GdipImageText(Graphics,"六",6 * *Date\WeekText\Width ,Y,*Date\WeekText\Width,*Date\WeekText\Height,*Date\WeekText\FontName,*Date\WeekText\FontSize,*Date\WeekText\FontStyle,*Date\DateArray[6]\DayText\TextColor,*Date\DateArray[6]\DayText\TextColor,*Date\WeekText\PenWidth,*Date\WeekText\Align,*Date\WeekText\Style)
  GdipDeleteGraphics(Graphics)
EndProcedure

Procedure DarwBack(*Date.GdipDate);绘制日历背景
  GdipGetImageGraphicsContext(*Date\Creat\ImageBack,@Graphics)
    *Date\BackYearText\Text=Str(*Date\Year)+"年" + Chr(10) +Str(*Date\Month)+ "月"
    GdipImageText(Graphics,*Date\BackYearText\Text,*Date\BackYearText\X ,*Date\BackYearText\Y,*Date\BackYearText\Width,*Date\BackYearText\Height,*Date\BackYearText\FontName,*Date\BackYearText\FontSize,*Date\BackYearText\FontStyle,*Date\BackYearText\TextColor,*Date\BackYearText\PenColor,*Date\BackYearText\PenWidth,*Date\BackYearText\Align,*Date\BackYearText\Style)
  GdipDeleteGraphics(Graphics)
EndProcedure

Procedure DrawDay(*Date.GdipDate,Day);绘制天
  Week=Weekday(*Date\Year,*Date\Month,1)
  *Ftv.DateFtv=*Date\DateArray[Week+Day - 1]
  GdipGetImageGraphicsContext(*Date\Creat\ImageBack,@Graphics)
    
    If *Ftv\BackImage
      GdipSetCompositingMode(Graphics,#CompositingModeSourceCopy)
      GdipDrawImageRect(Graphics,*Ftv\BackImage,*Ftv\X,*Ftv\Y,*Ftv\Width,*Ftv\Height)
      
    Else 
       GdipCreateBitmapFromScan0(*Ftv\Width,*Ftv\Height,0,#GDIPLUS_PIXELFORMAT_32bppARGB, 0,@*Ftv\BackImage)
       GdipGetImageGraphicsContext(*Ftv\BackImage,@dGraphics)
         GdipSetCompositingMode(dGraphics,#CompositingModeSourceCopy)
         GdipDrawImageRectRectI(dGraphics,*Date\Creat\ImageBack,0,0,*Ftv\Width,*Ftv\Height,*Ftv\X,*Ftv\Y,*Ftv\Width,*Ftv\Height, #UnitPixel,#Null, #Null, #Null)
       GdipDeleteGraphics(dGraphics)
    EndIf 
    
    GdipSetCompositingMode(Graphics,#CompositingModeSourceOver)
    
    If *Ftv\OnImage
      GdipDrawImageRect(Graphics,*Ftv\OnImage,*Ftv\X,*Ftv\Y,*Ftv\Width,*Ftv\Height)
    EndIf
    
    If *Ftv\Image
      GdipDrawImageRect(Graphics,*Ftv\Image,*Ftv\X,*Ftv\Y,*Ftv\Width,*Ftv\Height)
    EndIf
    
    GdipImageText(Graphics,*Ftv\DayText\Text,*Ftv\DayText\X ,*Ftv\DayText\Y,*Ftv\DayText\Width,*Ftv\DayText\Height,*Ftv\DayText\FontName,*Ftv\DayText\FontSize,*Ftv\DayText\FontStyle,*Ftv\DayText\TextColor,*Ftv\DayText\PenColor,*Ftv\DayText\PenWidth,*Ftv\DayText\Align,*Ftv\DayText\Style)
    If Len(*Ftv\LDayText\Text) > 5
       GdipImageText(Graphics,Left(*Ftv\LDayText\Text,4) + "...",*Ftv\LDayText\X ,*Ftv\LDayText\Y,*Ftv\LDayText\Width,*Ftv\LDayText\Height,*Ftv\LDayText\FontName,*Ftv\LDayText\FontSize,*Ftv\LDayText\FontStyle,*Ftv\LDayText\TextColor,*Ftv\LDayText\PenColor,*Ftv\LDayText\PenWidth,*Ftv\LDayText\Align,*Ftv\LDayText\Style)
    Else 
      GdipImageText(Graphics,*Ftv\LDayText\Text,*Ftv\LDayText\X ,*Ftv\LDayText\Y,*Ftv\LDayText\Width,*Ftv\LDayText\Height,*Ftv\LDayText\FontName,*Ftv\LDayText\FontSize,*Ftv\LDayText\FontStyle,*Ftv\LDayText\TextColor,*Ftv\LDayText\PenColor,*Ftv\LDayText\PenWidth,*Ftv\LDayText\Align,*Ftv\LDayText\Style)
    EndIf 
    
    If *Ftv\ToDayImage
      GdipDrawImageRect(Graphics,*Ftv\ToDayImage,*Ftv\X,*Ftv\Y,*Ftv\Width,*Ftv\Height)
    EndIf
 GdipDeleteGraphics(Graphics)     
EndProcedure

Procedure FreeDrawBack(*Date.GdipDate)
  GdipDisposeImage(*Date\TitleBack)
  *Date\TitleBack=0
  For I=0 To 41
    *Ftv.DateFtv=*Date\DateArray[I]
    GdipDisposeImage(*Ftv\BackImage)
    *Ftv\Image = 0
    *Ftv\ToDayImage = 0
    *Ftv\OnImage = 0
    *Ftv\BackImage = 0 
  Next
  GdipDisposeImage(*Date\Creat\ImageBack)
  GdipCloneImage(*Date\Image,@*Date\Creat\ImageBack)
EndProcedure

Procedure DefaultParameters(*Date.GdipDate)
     *Date\DayWidth=70
     *Date\DayHeight=42
     *Date\DayTop=10
     *Date\sColor=$FF0000FF
     *Date\lColor=$FFFF0000
     *Date\wColor=$FFFF00FF
     *Date\tColor=$FF00FF00
     
     *Date\SundayColor.l =$FFFF0000
     *Date\SaturdayColor.l=$FF0000FF
     
;      *Date\MoveColor=$0
    *Date\ToDayImage=GdipCatchImage(?ToDayImage,?OnDayImage-?ToDayImage)
    *Date\OnImage=GdipCatchImage(?OnDayImage,?WeekImage-?OnDayImage)
    *Date\WeekImage=GdipCatchImage(?WeekImage,?EndDateImage-?WeekImage)
    *Date\TitleImage=GdipCatchImage(?TitleImage,?ToDayImage-?TitleImage)
     
;      *Date\TeitleX=0
;      *Date\TeitleY=0
     
     *Date\TeitleHeight=25
     *Date\IsTitle=1
     *Date\sTitle\FontName="宋体"
     *Date\sTitle\FontSize=16
     *Date\sTitle\FontStyle=1
     *Date\sTitle\TextColor=$FFFFFFFF
     *Date\sTitle\PenWidth=1
     *Date\sTitle\PenColor=$0
     *Date\sTitle\Align= #GD_TextAlignRight | #GD_TextLineAlignCenter
     *Date\sTitle\Style=4
     *Date\sTitle\X=0
     *Date\sTitle\Y=2
     *Date\sTitle\Width=160
     *Date\sTitle\Height=25
     
     *Date\lTitle\FontName="宋体"
     *Date\lTitle\FontSize=16
     *Date\lTitle\FontStyle=1
     *Date\lTitle\TextColor=$FFFFFF00
     *Date\lTitle\PenWidth=0
     *Date\lTitle\PenColor=$0
     *Date\lTitle\Align=#GD_TextLineAlignCenter | #GD_TextAlignCenter 
     *Date\lTitle\Style=4
     *Date\lTitle\X=*Date\sTitle\Width + *Date\sTitle\X
     *Date\lTitle\Y=2
     *Date\lTitle\Width=230
     *Date\lTitle\Height=*Date\sTitle\Height
     
     *Date\wTitle\FontName="宋体"
     *Date\wTitle\FontSize=16
     *Date\wTitle\FontStyle=1
     *Date\wTitle\TextColor=$FF00FF00
     *Date\wTitle\PenWidth=0
     *Date\wTitle\PenColor=$0
     *Date\wTitle\Align= #GD_TextLineAlignCenter
     *Date\wTitle\Style=4
     *Date\wTitle\X=*Date\lTitle\X+*Date\lTitle\Width
     *Date\wTitle\Y=2
     *Date\wTitle\Width=100
     *Date\wTitle\Height=*Date\sTitle\Height
     *Date\TeitleWidth=*Date\wTitle\Width + *Date\wTitle\X

     *Date\IsBack=1
     *Date\BackYearText\FontName="黑体"
     *Date\BackYearText\FontSize=100
     *Date\BackYearText\FontStyle=1
     *Date\BackYearText\TextColor=$20808080
     *Date\BackYearText\PenWidth=2
     *Date\BackYearText\PenColor=$10FFFF00
     *Date\BackYearText\Align= #GD_TextAlignCenter
     *Date\BackYearText\Style=4
     *Date\BackYearText\X=1
     *Date\BackYearText\Y=50
     *Date\BackYearText\Width=*Date\DayWidth * 7
     *Date\BackYearText\Height=300
      

     *Date\IsWeek=1
     *Date\WeekText\FontName="黑体"
     *Date\WeekText\FontSize=18
     *Date\WeekText\FontStyle=1
     *Date\WeekText\TextColor=$FF000000
     *Date\WeekText\PenWidth=1
     *Date\WeekText\PenColor=$FF000000
     *Date\WeekText\Align= #GD_TextAlignCenter
     *Date\WeekText\Style=4
     *Date\WeekText\X=0
     *Date\WeekText\Y=5
     *Date\WeekText\Width=*Date\DayWidth
     *Date\WeekText\Height=20
      
     *Date\DText\FontName="Arial Black"
     *Date\DText\FontSize=22
     *Date\DText\TextColor=$FF000000
     *Date\DText\PenWidth=1
     *Date\DText\PenColor=$B0FFFFFF
     *Date\DText\Align= #GD_TextAlignCenter
     *Date\DText\Style=4
     *Date\DText\X=0
     *Date\DText\Y=0
     *Date\DText\Width=*Date\DayWidth
     *Date\DText\Height=25

     *Date\LDText\FontName="宋体"
     *Date\LDText\FontSize=12
     *Date\LDText\TextColor=$FF000000
     *Date\LDText\PenWidth=0
     *Date\LDText\PenColor=0
     *Date\LDText\Align= #GD_TextAlignCenter
     *Date\LDText\Style=0
     *Date\LDText\X=0
     *Date\LDText\Y=27
     *Date\LDText\Width=*Date\DayWidth
     *Date\LDText\Height=14
EndProcedure

Procedure DrawDate(*Date.GdipDate)
     FreeDrawBack(*Date)
     SetStartDate(*Date)
     SetArrayDate(*Date)
     
     If *Date\IsTitle
       DrawTitle(*Date.GdipDate,*Date\Day)
       WHeight = *Date\sTitle\Height
     EndIf 
          
     WHeight + *Date\WeekText\Y
     If *Date\IsWeek
       DrawWeekT(*Date.GdipDate,WHeight )
     EndIf 
     
     If *Date\IsBack
       DarwBack(*Date)
     EndIf 
     
     Day=SolarDays(*Date\Year,*Date\Month)
     For D=1 To Day
       DrawDay(*Date.GdipDate,D)
     Next
EndProcedure

Procedure IDatText(*Date.GdipDate,Text.s)
   
EndProcedure

Procedure IDatSize(*Date.GdipDate,Width,Height)

  ProcedureReturn #PB_ProcessPureBasicEvents 
EndProcedure

Procedure IDatLoad(*Date.GdipDate)
  DefaultParameters(*Date.GdipDate)
  DrawDate(*Date)
EndProcedure

Procedure IDatDraw(*Date.GdipDate,*Gadget.PWnd,*cRect.RECT)
  
EndProcedure

Procedure IsDay(*Date.GdipDate,X,Y) ;判断鼠标位置
   Week=Weekday(*Date\Year,*Date\Month,1)
   Day=SolarDays(*Date\Year,*Date\Month) + Week-1
   
   For Week = Week To Day
     *Ftv.DateFtv=*Date\DateArray[Week]
     If *Ftv\X < X And X < *Ftv\X + *Ftv\Width And *Ftv\Y < Y And Y <*Ftv\Y + *Ftv\Height
        ProcedureReturn *Ftv
     EndIf 
   Next
EndProcedure 

Procedure MousEvent(*Date.GdipDate,*Ftv.DateFtv,hWnd, uMsg, wParam, lParam)
  Select uMsg
    Case #WM_MOUSEMOVE

    Case #WM_MouseToLeave
      *Ftv\DayText\PenWidth=*Date\DText\PenWidth
      *Ftv\DayText\PenColor=*Date\DText\PenColor
      
  EndSelect
EndProcedure

Procedure IDatEvent(*Date.GdipDate,hWnd, uMsg, wParam, lParam)
  If *Date\Enabled =3
    ProcedureReturn  1
  EndIf 
  Select uMsg
    Case #WM_MOUSEMOVE,#WM_LBUTTONDOWN
      *Ftv.DateFtv=IsDay(*Date.GdipDate,LOWORD(lParam)-*Date\X,HIWORD(lParam)-*Date\Y)
      If *Ftv
        Select uMsg
         Case #WM_MOUSEMOVE
          If *Date\UpGadget<>*Ftv
            *Ftv\DayText\PenWidth=2
            *Ftv\DayText\PenColor= *Date\MoveColor
            DrawDay(*Date,*Ftv\Day)
            T=*Ftv
            If *Date\UpGadget
              *Ftv=*Date\UpGadget
              *Ftv\DayText\PenWidth=*Date\DText\PenWidth
              *Ftv\DayText\PenColor=*Date\DText\PenColor
              DrawDay(*Date,*Ftv\Day)
            EndIf 
            *Date\UpGadget=T
          EndIf
          SendMessage_(Hwnd,#WM_Draw,*Date,@*Date\X)
         Case #WM_LBUTTONDOWN
           *Ftv\OnImage= *Date\OnImage
           DrawDay(*Date,*Ftv\Day)
           DrawTitle(*Date,*Ftv\Day)
           T=*Ftv
           If *Date\OnGadget<>*Ftv And *Date\OnGadget
             *Ftv=*Date\OnGadget
             *Ftv\OnImage= 0
             DrawDay(*Date,*Ftv\Day)
           EndIf 
           *Date\OnGadget = T
          SendMessage_(Hwnd,#WM_Draw,*Date,@*Date\X)
        EndSelect
      EndIf 
  EndSelect
  ProcedureReturn  1
EndProcedure

Procedure IDatIsLoca(*Date.GdipDate,hWnd,X,Y)
  X-*Date\X
  Y-*Date\Y
  If X>-1 And Y>-1 And X<*Date\Width And Y<*Date\Height  And *Date\Visible
      GdipBitmapGetPixel(*Date\Creat\ImageBack,X,Y,@Color)
      If GdipAlpha(Color)
        ProcedureReturn *Date
      EndIf 
  EndIf 
EndProcedure

Procedure IDatFree(*Date.GdipDate)
  FreeDrawBack(*Date)
  GdipDisposeImage(*Date\Image)  ;当前绘制的图片
  GdipDisposeImage(*Date\Draw)
  GdipDisposeImage(*Date\Creat\ImageBack)   ;绘制缓冲
  DeleteWindowList(*Date)
EndProcedure

Procedure GdipCreateDate(*Hwnd.PWnd,Image,X,Y,Width=504,Height=305,Style=6,ModeSource=#CompositingModeSourceOver)
 *Date.GdipDate=AddWindowList(@*Hwnd\Gadget,SizeOf(GdipDate))
 *Date\Year=Year(Date())
 *Date\Month=Month(Date())
 *Date\Day=Day(Date())
 If Image
    GdipCloneImage(Image,@*Date\Image)
    GdipGetImageWidth(Image,@Width )
    GdipGetImageHeight(Image,@Height)
 Else 
    GdipCreateBitmapFromScan0(Width,Height,0,#GDIPLUS_PIXELFORMAT_32bppARGB, 0,@*Date\Image)
 EndIf 
 With *Date\Creat\Text
   \FontName="宋体"
   \FontSize=15
   \FontStyle=1
   \TextColor=$FF000000
   \Align= #GD_TextLineAlignCenter | #GD_TextAlignCenter
   \Style=4
 EndWith
 With *Date
    \X=X
    \Y=Y
    \Width=Width
    \Height=Height
    \ModeSource=ModeSource
    \Visible=IsVal(Style,#Visible)
    \Enabled=(1-IsVal(Style,#Enabled))*3
    \Type= #Date
    \Style=IsVal(Style,1)
    \HostGadget=*Hwnd
    *Hwnd\NewGadget=*Date
    \wIsLoca=@IDatIsLoca()
    \wLoad=@IDatLoad()
    \wDraw=@IDatDraw()
    \wEvent=@IDatEvent()
    \wFree=@IDatFree()
    \wSize=@IDatSize()
    \wText=@IDatText()   
  EndWith
  ProcedureReturn *Date
EndProcedure

Procedure SetDate(*Date.GdipDate,Year=0,Month=0,Day=0)
 If *Date\Year<>Year Or *Date\Month<>Month Or *Date\Day<>Day
   If Year<>0
     *Date\Year=Year
   EndIf 
   If Month<>0
    *Date\Month=Month
   EndIf 
   If Day <>0
     *Date\Day=Day
   EndIf 
   DrawDate(*Date.GdipDate)
   SendMessage_(WindowID(PeekL(GadgetGetWindowID(*Date)+SizeOf(PWnd))),#WM_Draw,*Date,@*Date\X)
 EndIf 
EndProcedure

Procedure GetDateYear(*Date.GdipDate)
  ProcedureReturn *Date\Year
EndProcedure

Procedure GetDateMonth(*Date.GdipDate)
  ProcedureReturn *Date\Month
EndProcedure

Procedure GetDateDay(*Date.GdipDate)
  ProcedureReturn *Date\Day
EndProcedure

DataSection
TitleImage:
  IncludeBinary "Image\Date\Title.png"
ToDayImage:
  IncludeBinary "Image\Date\ToDay.Png"
OnDayImage:
  IncludeBinary "Image\Date\OnDay.Png"
WeekImage:
  IncludeBinary "Image\Date\Week.png"
EndDateImage:
EndDataSection

; IDE Options = PureBasic 5.11 (Windows - x64)
; CursorPosition = 295
; FirstLine = 98
; Folding = kOI-
; EnableAsm
; EnableUnicode
; EnableXP